package cn.xwt.weidisk.util;

import cn.xwt.weidisk.mapper.FileMapper;
import cn.xwt.weidisk.mapper.UserMapper;
import cn.xwt.weidisk.service.FileService;
import cn.xwt.weidisk.service.UserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author 薛慰涛
 */
@Component
public class DiskUtils {
    @Resource
    FileMapper fileMapper;

    @Resource
    UserMapper userMapper;

    /**
     * 判断容量是否足够
     * @param append 要添加的字节
     * @param uid 用户id
     * @return boolean
     */
    public Boolean isEnough(Long append, Long uid) {
        long capacity = (long)userMapper.selectCapacity(uid) * 1024 * 1024 * 1024;
        Long used = fileMapper.selectUsed(uid);
        used = used == null ? 0 : used;
        return (used + append) <= capacity;
    }
}
